'''
Created on Apr 1, 2012

@author: Johnathon
'''
from Gates.Gate import Gate
from LineValues import Zero, One

class OrGate(Gate):
    '''
    classdocs
    '''

#    outputTable ={"X": {"X":"X", "1":"1", "0":"X", "D":"X", "D'":"X"},
#                  "1": {"X":"1", "1":"1", "0":"1", "D":"1", "D'":"1"},
#                  "0": {"X":"X", "1":"1", "0":"0", "D":"D", "D'":"D'"},
#                  "D": {"X":"X", "1":"1", "0":"D", "D":"D", "D'":"1"},
#                  "D'": {"X":"X", "1":"1", "0":"D'", "D":"1", "D'":"D'"},
#                  }

    def __init__(self, gateName, level, inputLines, outputLine):
        '''
        Constructor
        '''
        super(OrGate, self).__init__(gateName, level, inputLines, outputLine)
#        self.gateName = gateName
#        self.level = level
#        self.inputs = inputLines
#        self.output = outputLine
        
    def evaluate(self):
        result = Zero
        for inputVal in self.inputs:
            result = inputVal.value.OR(result)
#            if inputVal.value == "1":
#                result = "1"
#                break
#            result = OrGate.outputTable[result][inputVal.value]
        if self.output is not None:
            self.output.driveValue(result)
            
    def getEquivalentFaults(self):
        faults = [(i, One) for i in self.inputs]
        faults.append((self.output, One))
        return [faults]